<?php
/**
 * Created by PhpStorm.
 * User: qhzhyt
 * Date: 2018/10/5
 * Time: 20:59
 */

require_once '../conf/conf.php';
require_once '../lib/ImageTool.php';

$cover_path = '../files/img/logo.png';
if (isset($_GET['mapId'])) {
    $map = $db->get('map', '*', ['map_id' => $_GET['mapId']]);
    if ($map) {
        $cover_path = '../files/upload/cover/cover_' . $_GET['mapId'] . '_' . substr($map['map_hash'], 16) . '.png';
    }
}

if (!file_exists($cover_path)) {
    $cover_path = '../files/img/logo.png';
}
// var_dump($cover_path);

if (isset($_GET['coverWidth']) && $_GET['coverWidth'] > 30) {
    $cover_img = new ImageTool($cover_path);
    $cover_img->compressImage($_GET['coverWidth']);
    $cover_img->showImage();
} else {
    header('content-type:image/png;');
    $img = file_get_contents($cover_path);
    echo $img;
}